package com.rtx.edi.platform.source.controller;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rtx.api.enums.FieldValidateType;
import com.rtx.api.utils.FieldValidateUtils;
import com.rtx.edi.model.express.po.PlExpressApiConfig;
import com.rtx.edi.model.response.EdiResponse;
import com.rtx.edi.platform.source.bean.PlExpressSourceData;
import com.rtx.edi.platform.source.bean.PlExpressSourceDetail;
import com.rtx.edi.platform.source.service.PlExpressSourceDetailService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@SuppressWarnings("all")
@Api(tags = {"源数据明细"})
@RestController
@RequestMapping("/v1/PlExpressSourceDetail")
public class PlExpressSourceDetailController {

	@Autowired
	PlExpressSourceDetailService configService;
	
    /**
     * 获取源数据明细列表
     * @return
     */
    @ApiOperation(value = "源数据明细列表", notes = "分页获取源数据明细列表")
    @PostMapping("selectExpressSourceDataList")
    public EdiResponse selectPlExpressSourceDetailPageList(@RequestBody PlExpressSourceDetail dto){
        Page<PlExpressSourceDetail> pageParam = new Page<>(dto.getPageNum(), dto.getPageSize());
        configService.selectList(pageParam,dto);
        return EdiResponse.success().data("page",pageParam);
    }

    /**
     * 获取源数据明细
     * @return
     */
    @ApiOperation(value = "获取源数据明细", notes = "根据ID获取源数据明细")
    @PostMapping("selectExpressSourceDetailById")
    public EdiResponse selectExpressApiConfigById(@RequestBody PlExpressSourceDetail dto){
        return EdiResponse.success().data("item",configService.getById(dto.getId()));
    }

    /**
     * 新增源数据明细
     * @return
     */
    @ApiOperation(value = "新增源数据明细", notes = "新增源数据明细")
    @PostMapping("addPlExpressSourceDetail")
    public EdiResponse addExpressApiConfig(@RequestBody PlExpressSourceDetail dto){
        configService.addData("ris_edi", dto);
        return  EdiResponse.success() ;
    }

    /**
     * 修改源数据明细
     * @return
     */
    @ApiOperation(value = "修改源数据明细", notes = "根据ID修改源数据明细")
    @PostMapping("editPlExpressSourceDetail")
    public EdiResponse editExpressApiConfig(@RequestBody PlExpressSourceDetail dto){
    	configService.updateById(dto);
        return  EdiResponse.success();
    }

    /**
     * 删除源数据明细
     * @return
     */
    @ApiOperation(value = "删除源数据明细", notes = "根据ID删除源数据明细")
    @PostMapping("deletePlExpressSourceDetail")
    public EdiResponse deletePlApplicationFieldById(@RequestBody PlExpressSourceDetail dto){
        FieldValidateUtils.fieldNotNull(dto,FieldValidateType.DELETE);
        return  configService.removeById(dto.getId()) ? EdiResponse.success() : EdiResponse.failed();
    }

    /**
     * 批量删除源数据明细
     * @return
     */
    @ApiOperation(value = "批量删除源数据明细", notes = "批量删除源数据明细")
    @PostMapping("deletePlExpressSourceDetailIds")
    public EdiResponse deletePlApplicationFieldByIds(@RequestBody List<PlExpressSourceDetail> list){
        List<Long> ids = list.stream().map(p -> p.getId()).distinct().collect(Collectors.toList());
        return  configService.removeBatchByIds(ids) ? EdiResponse.success() : EdiResponse.failed();
    }
}
